package com.neusoft.care.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.neusoft.care.dao.CareLevelDao;
import com.neusoft.care.po.CareLevel;
import com.neusoft.care.po.ResponseBean;
import com.neusoft.care.service.CareLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CareLevelServiceImpl implements CareLevelService {

    @Autowired
    private CareLevelDao careLevelDao;

    @Override
    public ResponseBean<List<CareLevel>> getAllCareLevels() {
        List<CareLevel> careLevels = careLevelDao.selectList(null);
        return new ResponseBean<>(careLevels);
    }

    @Override
    public ResponseBean<CareLevel> getCareLevelById(Integer levelId) {
        CareLevel careLevel = careLevelDao.selectById(levelId);
        if (careLevel != null) {
            return new ResponseBean<>(careLevel);
        } else {
            return new ResponseBean<>(404, "护理级别未找到");
        }
    }

    @Override
    public ResponseBean<Integer> addCareLevel(CareLevel careLevel) {
        int result = careLevelDao.insert(careLevel);
        if (result > 0) {
            return new ResponseBean<>(result); // 返回插入成功的行数
        } else {
            return new ResponseBean<>(500, "护理级别添加失败");
        }
    }

    @Override
    public ResponseBean<Integer> updateCareLevel(CareLevel careLevel) {
        int result = careLevelDao.updateById(careLevel);
        if (result > 0) {
            return new ResponseBean<>(result); // 返回更新成功的行数
        } else {
            return new ResponseBean<>(500, "护理级别信息更新失败");
        }
    }

    @Override
    public ResponseBean<Integer> deleteCareLevel(Integer levelId) {
        int result = careLevelDao.deleteById(levelId);
        if (result > 0) {
            return new ResponseBean<>(result); // 返回删除成功的行数
        } else {
            return new ResponseBean<>(500, "护理级别删除失败");
        }
    }

    @Override
//    根据状态查询护理级别
    public ResponseBean<List<CareLevel>> getAllCareLevelsByStatus(String status) {
        List<CareLevel> careLevels = careLevelDao.selectList(new QueryWrapper<CareLevel>().eq("status", status));
        if (careLevels != null && !careLevels.isEmpty()) {
            return new ResponseBean<>(careLevels);
        } else {
            return new ResponseBean<>(500, "没有找到护理级别");
        }
    }
}